package com.sirc.zp.sqlprovider;

import com.sirc.zp.domain.FamilyAudit;
import org.apache.ibatis.jdbc.SQL;

public class FamilyAuditProvider {
    /**
     * 通过id得到FamilyAudit实体
     * @param id
     * @return
     */
    public String getFamilyAuditById(Integer id){
        return new SQL()
        {{
            SELECT("*");
            FROM("familyaudit");
            WHERE("faid="+id);
        }}.toString();
    }
    /**
     * 通过uid得到FamilyAudit实体
     * @param uid
     * @return
     */
    public String getFamilyAuditByUId(Integer uid){
        return new SQL()
        {{
            SELECT("*");
            FROM("familyaudit");
            WHERE("uid="+uid);
        }}.toString();
    }
    /**
     * 通过status得到FamilyAudit实体
     * @param status
     * @return
     */
    public String getFamilyAuditByStatus(Integer status){
        return new SQL()
        {{
            SELECT("*");
            FROM("familyaudit");
            WHERE("status="+status);
        }}.toString();
    }
    /**
     * 提交一个族谱审核
     * @param familyAudit 族谱审核信息
     * @return
     */
    public String addFamilyAudit(FamilyAudit familyAudit){
        return new SQL(){{
            INSERT_INTO("familyaudit");
            if(familyAudit.getTitle()!=null)
            {
                VALUES("title", "#{title}");
            }
            if(familyAudit.getContent()!=null)
            {
                VALUES("content", "#{content}");
            }
            if(familyAudit.getUid()!=null)
            {
                VALUES("uid", "#{uid}");
            }
            if(familyAudit.getStatus()!=null)
            {
                VALUES("status", "#{status}");
            }
            if(familyAudit.getComment()!=null)
            {
                VALUES("comment", "#{comment}");
            }
            if(familyAudit.getIsdelete()!=null)
            {
                VALUES("isdelete", "#{isdelete}");
            }
        }}.toString();
    }
    /**
     * 更新族谱审核信息
     * @param familyAudit
     * @return
     */
    public String updateFamilyAudit(FamilyAudit familyAudit){
        return new SQL()
        {{
            UPDATE("familyaudit");
            if(familyAudit.getTitle()!=null)
            {
                SET("title=#{title}");
            }
            if(familyAudit.getContent()!=null)
            {
                SET("content=#{content}");
            }
            if(familyAudit.getUid()!=null)
            {
                SET("uid=#{uid}");
            }
            if(familyAudit.getStatus()!=null)
            {
                SET("status=#{status}");
            }
            if(familyAudit.getComment()!=null)
            {
                SET("comment=#{comment}");
            }
            if(familyAudit.getIsdelete()!=null)
            {
                SET("isdelete=#{isdelete}");
            }
            WHERE("faid = #{faid}");
        }}.toString();
    }
    /**
     * 通过主键删除审核信息
     * @param id
     * @return
     */
    public String deleteFamilyAudit(Integer id){
        return new SQL()
        {{
            DELETE_FROM("familyaudit");
            WHERE("faid="+id);
        }}.toString();
    }
}
